package com.itheima.jobs;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;

/**
 * @description: 定时清理预约设置
 * @author: Spark
 * @date: 2020/2/25-10:32
 * @Version: 1.0.0
 */
@Component
public class ClearOrderSettingJob {
    @Reference
    OrderSettingService orderSettingService;

    public void clearOrderSetting() throws Exception {
        System.out.println("清理任务执行了");
        //获取当前月最后一天
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));

        String lastDayOfThisMonth= DateUtils.parseDate2String(calendar.getTime());

        orderSettingService.clearOrderSettingBeforeDate(lastDayOfThisMonth);
    }
}